package com.training.android.simplelist;

import java.util.ArrayList;

import android.app.ListActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.Toast;

public class SimpleListActivity extends ListActivity {
	/** Called when the activity is first created. */

	ArrayList<String> data;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		//setContentView(R.layout.activity_main);

		getData();
		ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
				android.R.layout.simple_list_item_1, data);
		setListAdapter(adapter);
		getListView().setOnItemClickListener(new OnItemClickListener() {
			@Override
			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id) {
				Toast.makeText(getApplicationContext(), data.get(position).toString(), Toast.LENGTH_SHORT).show();
			}
		});
	}

	public void getData() {
		data = new ArrayList<String>();
		data.add("a1");
		data.add("a2");
		data.add("a3");
		data.add("a4");
		data.add("a5");
		data.add("a6");
		data.add("a7");
		data.add("a8");
		data.add("a9");
		data.add("a10");
	}
}